/**
 * dataList
 * Ivan Shine May 09
 */

(function($){
	$.fn.dataList=function(oD, oT) {
		if(!$.isArray(oD)) {
			throw "showResults expects an array";
		}
		var o = {
			tpl: '',
			limit: 5,
			callback: null
		};
		
		var p = {
			r: oD
		};
		if(oT)
		{
			$.extend(o, oT);
		}
		
		return this.each(function() {
			var self = this;
			
			self.showData = function() {
				for(var tx = 0; tx < o.limit; tx++) {
					var template = o.tpl;

					for(var k in p.r[tx]) {
						var regex = new RegExp("%"+ k +"%", "g");
						template = template.replace(regex, p.r[tx][k]);
					}
					$(this).append(template);
				}
				
				if(typeof o.callback == "function") {
					o.callback();
				}
			}
			self.showData();
		});
	}
})(jQuery);